package com.cppsu.cgx.libraryseatselection.mapper;

import static com.cppsu.cgx.libraryseatselection.mapper.FloorDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import com.cppsu.cgx.libraryseatselection.entity.Floor;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface FloorMapper {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    BasicColumn[] selectList = BasicColumn.columnList(id, libraryId, floorNumber, openStatus, x, y);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="record.id", before=false, resultType=Long.class)
    int insert(InsertStatementProvider<Floor> insertStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("FloorResult")
    Optional<Floor> selectOne(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="FloorResult", value = {
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="library_id", property="libraryId", jdbcType=JdbcType.BIGINT),
        @Result(column="floor_number", property="floorNumber", jdbcType=JdbcType.INTEGER),
        @Result(column="open_status", property="openStatus", jdbcType=JdbcType.INTEGER),
        @Result(column="x", property="x", jdbcType=JdbcType.INTEGER),
        @Result(column="y", property="y", jdbcType=JdbcType.INTEGER)
    })
    List<Floor> selectMany(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, floor, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, floor, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int deleteByPrimaryKey(Long id_) {
        return delete(c -> 
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insert(Floor record) {
        return MyBatis3Utils.insert(this::insert, record, floor, c ->
            c.map(libraryId).toProperty("libraryId")
            .map(floorNumber).toProperty("floorNumber")
            .map(openStatus).toProperty("openStatus")
            .map(x).toProperty("x")
            .map(y).toProperty("y")
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insertSelective(Floor record) {
        return MyBatis3Utils.insert(this::insert, record, floor, c ->
            c.map(libraryId).toPropertyWhenPresent("libraryId", record::getLibraryId)
            .map(floorNumber).toPropertyWhenPresent("floorNumber", record::getFloorNumber)
            .map(openStatus).toPropertyWhenPresent("openStatus", record::getOpenStatus)
            .map(x).toPropertyWhenPresent("x", record::getX)
            .map(y).toPropertyWhenPresent("y", record::getY)
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<Floor> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, floor, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<Floor> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, floor, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<Floor> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, floor, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<Floor> selectByPrimaryKey(Long id_) {
        return selectOne(c ->
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, floor, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateAllColumns(Floor record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(libraryId).equalTo(record::getLibraryId)
                .set(floorNumber).equalTo(record::getFloorNumber)
                .set(openStatus).equalTo(record::getOpenStatus)
                .set(x).equalTo(record::getX)
                .set(y).equalTo(record::getY);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(Floor record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(libraryId).equalToWhenPresent(record::getLibraryId)
                .set(floorNumber).equalToWhenPresent(record::getFloorNumber)
                .set(openStatus).equalToWhenPresent(record::getOpenStatus)
                .set(x).equalToWhenPresent(record::getX)
                .set(y).equalToWhenPresent(record::getY);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKey(Floor record) {
        return update(c ->
            c.set(libraryId).equalTo(record::getLibraryId)
            .set(floorNumber).equalTo(record::getFloorNumber)
            .set(openStatus).equalTo(record::getOpenStatus)
            .set(x).equalTo(record::getX)
            .set(y).equalTo(record::getY)
            .where(id, isEqualTo(record::getId))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKeySelective(Floor record) {
        return update(c ->
            c.set(libraryId).equalToWhenPresent(record::getLibraryId)
            .set(floorNumber).equalToWhenPresent(record::getFloorNumber)
            .set(openStatus).equalToWhenPresent(record::getOpenStatus)
            .set(x).equalToWhenPresent(record::getX)
            .set(y).equalToWhenPresent(record::getY)
            .where(id, isEqualTo(record::getId))
        );
    }
}